package com.example.app1;

import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

public class AlertDialogActivity extends AppCompatActivity implements View.OnClickListener {

    private TextView tv;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_alertdialog);
        Button btn = findViewById(R.id.btn_del);
        btn.setOnClickListener(this);
        tv = findViewById(R.id.tv);

    }

    @Override
    public void onClick(View v) {

        AlertDialog.Builder builder=new AlertDialog.Builder(this);
        //设置提醒对话框的标题
        builder.setTitle("尊敬的用户");
        //设置提醒对话框的内容文本
        builder.setMessage("真的要卸载我吗？");
        //设置对话框的肯定按钮文本及其点击监听器
        builder.setPositiveButton("残忍卸载", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                tv.setText("虽然依依不舍,但是只能离开了");
            }
        });
        builder.setNegativeButton("我在想想", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                tv.setText("谢谢你让我留在你身边");
            }
        });
        AlertDialog alertDialog = builder.create();
        alertDialog.show();
    }
}
